package com.cgg.stock.common.util;

import com.alibaba.druid.filter.config.ConfigTools;
import com.alibaba.druid.util.DruidPasswordCallback;
import com.alibaba.druid.util.StringUtils;

import java.util.Properties;

public class DBPasswordCallback extends DruidPasswordCallback {
    static final String PUBLIC_KEY = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAPcn9PKpyA2qNLemkezCqtRC+jezDafomuJNLfolPdGIHtQdhnJlBvfVuuMXU2AwAEUr7VlHQIFvioOgSeF3OkMCAwEAAQ==";


    @Override
    public void setProperties(Properties properties) {
        super.setProperties(properties);
        //获取配置文件中的已经加密的密码
        String pwd = (String)properties.get("password");
        if (!StringUtils.isEmpty(pwd)) {
            try {
                //这里的代码是将密码进行解密，并设置
                String password = ConfigTools.decrypt(PUBLIC_KEY, pwd);
                setPassword(password.toCharArray());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
